function loadEvent(nid){

	$.mobile.showPageLoadingMsg();

	$.ajax ({
		dataType: "json",
		url : "http://vlove.helia-agency.com/event/node/" + nid + ".json",
		success: function(result){
			console.log(result);

			showEvent(result);
		},
		error : function (XMLHttpRequest, textStatus, errorThrown){
			console.log("erreur : /n" + XMLHttpRequest + "erreur : /n" + textStatus + "erreur : /n" + errorThrown);
		}
	});

}

function showEvent(ev){
	var html = '<div class="fiche-event" id="event-"' + ev.nid + '"">';
	html += '<h2> Article du ' + ev.field_date.und[0]['value'] + '</h2>';
	html += '<div class="bloc_img"><img src="http://vlove.helia-agency.com/sites/default/files/styles/medium/public/evenement/' + ev.field_image.und[0]['filename'] + '" /></div>';
	html += '<p class="accroche"><strong>' + ev.field_accroche.und[0]['value'] + '</strong></p>';
	html += '<p class="description">' + ev.body.und[0]['value'] + '</p>';


	$('.page-event h1').text(ev.title);

	$('.page-event .ui-content').html("");
	$('.page-event .ui-content').prepend(html);

	$.mobile.hidePageLoadingMsg();
}

$(".page-event").on("pageshow", function (event, data) {
	$('.menu').load('menu.html',function(){ $('#menu').panel(); });
	
	var query = window.location.search;
	query = query.replace("?nid=","");

	loadEvent(query);
});

